#include "HUDplayerPosBehaviour.h"
#include "Transformation.h"
#include "GameObject.h"

using namespace game_engine;
using namespace game_engine::components;
using namespace game_engine::library;
using namespace game_engine::utils;

///////////////////////////////////////////////////////////////////////////////
// Constructors and Destructors
///////////////////////////////////////////////////////////////////////////////

HUDplayerPosBehaviour::HUDplayerPosBehaviour(void)
    : Behaviour(), subject(NULL), subjectPosition(), iconYmin(), iconYmax(), 
    state(NULL)
{
    type = "HUDplayerPosBehaviour";
    slotSubjectHasMoved.AssignFunction(this, &HUDplayerPosBehaviour::setSubjectPosition);
}

HUDplayerPosBehaviour::HUDplayerPosBehaviour(GameObject *obj)
    : Behaviour(obj), subject(NULL), subjectPosition(), iconYmin(), iconYmax(), 
    state(NULL)
{
    type = "HUDplayerPosBehaviour";
    slotSubjectHasMoved.AssignFunction(this, &HUDplayerPosBehaviour::setSubjectPosition);
}

HUDplayerPosBehaviour::~HUDplayerPosBehaviour(void)
{
    delete state;
}

///////////////////////////////////////////////////////////////////////////////
// Other public methods
///////////////////////////////////////////////////////////////////////////////

void HUDplayerPosBehaviour::initialize(void) throw(...)
{
    // Create states for this behaviour
    state = new MainPlayerPosState(this);
    setCurrentState(state);

    // Base class initialization
    Behaviour::initialize();
}

///////////////////////////////////////////////////////////////////////////////
// Slots
///////////////////////////////////////////////////////////////////////////////

INT32 HUDplayerPosBehaviour::setSubjectPosition(Point position)
{
    subjectPosition = position;
    return 0;
}

///////////////////////////////////////////////////////////////////////////////
// Getters
///////////////////////////////////////////////////////////////////////////////

//GameObject* HUDplayerPosBehaviour::getSubject(void) const
//{
//    return subject;
//}

const Point& HUDplayerPosBehaviour::getSubjectPosition(void) const
{
    return subjectPosition;
}

const FLOAT32 HUDplayerPosBehaviour::getIconYmin(void) const
{
    return iconYmin;
}

const FLOAT32 HUDplayerPosBehaviour::getIconYmax(void) const
{
    return iconYmax;
}

///////////////////////////////////////////////////////////////////////////////
// Setters
///////////////////////////////////////////////////////////////////////////////

void HUDplayerPosBehaviour::setSubject(GameObject *sbj) throw(...)
{
    Transformation *transf = dynamic_cast<Transformation*> 
        (sbj->getComponent("Transformation"));
    slotSubjectHasMoved.Connect(transf->signalNewPosition);
    subject = sbj;
}

void HUDplayerPosBehaviour::setIconYmin(const FLOAT32 val)
{
    iconYmin = val;
}

void HUDplayerPosBehaviour::setIconYmax(const FLOAT32 val)
{
    iconYmax = val;
}
